package com.chima.action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletContext;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import com.chima.domain.Department;
import com.chima.domain.Employees;
import com.chima.domain.Job;
import com.chima.domain.JobDetail;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.domain.Rate;
import com.chima.service.DepartmentService;
import com.chima.service.DetailPostService;
import com.chima.service.EmployeeService;
import com.chima.service.JobDetailService;
import com.chima.service.JobService;
import com.chima.service.RateService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import flexjson.JSONSerializer;
import flexjson.transformer.DateTransformer;
public class JobDetailAction extends ActionSupport implements ModelDriven<JobDetail> {
   JobDetail jobDetail= new JobDetail();
	public JobDetail getModel() {
		return jobDetail;
	}
	private int start;// 开始页码
	private int limit; //每页显示
	private int page;//页数
	private int jobId;
	private int id;//jobDetail 的id
	private int []ids;
	private Double []cores;
	private Double []pingjis;
	private String []names;//创建周计划
    private String []adcontents;
    private JobDetailService jobDetailService;
	private EmployeeService employeeService;
	private DepartmentService departmentService;
	private DetailPostService detailPostService ;
	private RateService rateService ;
	private JobService jobService;
	private List<JobDetail> jobDetails;
	private List<JobDetail> jobDetails1;
	private boolean success=false ;
	private int RateID;
	private int searchemp;  //查询个人项目化工作
	private String searchdate;
	private String creatdate;
	private File upload;
	private String uploadContentType;
	private String uploadFileName;
	
    public Double[] getCores() {
		return cores;
	}
	public void setCores(Double[] cores) {
		this.cores = cores;
	}
	public String getCreatdate() {
		return creatdate;
	}
	public void setCreatdate(String creatdate) {
		this.creatdate = creatdate;
	}
	public int getSearchemp() {
		return searchemp;
	}
	public void setSearchemp(int searchemp) {
		this.searchemp = searchemp;
	}
	public String getSearchdate() {
		return searchdate;
	}
	public void setSearchdate(String searchdate) {
		this.searchdate = searchdate;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadContentType() {
		return uploadContentType;
	}
	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public String getSerchdate() {
		return serchdate;
	}
	public void setSerchdate(String serchdate) {
		this.serchdate = serchdate;
	}
	private String serchdate;
	 
public void setRateService(RateService rateService) {
		this.rateService = rateService;
	}
public int getRateID() {
		return RateID;
	}
	public void setRateID(int rateID) {
		RateID = rateID;
	}

	public String[] getAdcontents() {
		return adcontents;
	}
	public void setAdcontents(String[] adcontents) {
		this.adcontents = adcontents;
	}
	public String[] getNames() {
		return names;
	}
	public void setNames(String[] names) {
		this.names = names;
	}
	
	public Double[] getPingjis() {
		return pingjis;
	}
	public void setPingjis(Double[] pingjis) {
		this.pingjis = pingjis;
	}
	public int[] getIds() {
		return ids;
	}
	public void setIds(int[] ids) {
		this.ids = ids;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getJobId() {
		return jobId;
	}
	public void setJobId(int jobId) {
		this.jobId = jobId;
	}
	
	public void setDetailPostService(DetailPostService detailPostService) {
		this.detailPostService = detailPostService;
	}
	public void setJobDetails1(List<JobDetail> jobDetails1) {
		this.jobDetails1 = jobDetails1;
	}
public DepartmentService getDepartmentService() {
		return departmentService;
	}
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}
public JobService getJobService() {
		return jobService;
	}
	public void setJobService(JobService jobService) {
		this.jobService = jobService;
	}
public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}
public JobDetailService getJobDetailService() {
		return jobDetailService;
	}
	public void setJobDetailService(JobDetailService jobDetailService) {
		this.jobDetailService = jobDetailService;
	}
	public List<JobDetail> getJobDetails() {
		return jobDetails;
	}
	public void setJobDetails(List<JobDetail> jobDetails) {
		this.jobDetails = jobDetails;
	}
public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}

public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	
//显示临时性工作详情及 临时性工作评价显示
public String  ListJobDetail() throws Exception{
	  Employees  existEmployee =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
	  PageRequestBean pageRequestBean = new PageRequestBean();
			//封装条件
			DetachedCriteria criteria = DetachedCriteria.forClass(JobDetail.class);
			if(jobId!=0){
				criteria.add(Restrictions.eq("job.id",jobId));
			}
		  if(serchdate==null || "".equals(serchdate)){
			    	 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			  	     Calendar  c = Calendar.getInstance();
			         c.set(Calendar.DAY_OF_YEAR, 1);//本年第一天
			         String first=sdf.format(c.getTime());
			         c.add(Calendar.YEAR, 1);
			         c.set(Calendar.DAY_OF_YEAR, 1);//本年最后一天
			         c.add(Calendar.DAY_OF_YEAR, -1);
			         String Last=sdf.format(c.getTime());
			         criteria.add(Restrictions.ge("startdate", sdf.parse(first)));
					 criteria.add(Restrictions.le("startdate", sdf.parse(Last)));
			    	
		  }
		  if(serchdate!=null && !"".equals(serchdate)){
				 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
				 int day=Integer.parseInt( serchdate.substring(5,7));
				 int year=Integer.parseInt( serchdate.substring(0,4));
				String  First =getFirstDayOfMonth(year,day);
				String  last =getLastDayOfMonth(year,day);
				criteria.add(Restrictions.ge("startdate", sdf.parse(First)));
				criteria.add(Restrictions.le("startdate", sdf.parse(last)));
			}
		  if(!existEmployee.getName().equals("admin")){
	    	  criteria.add(Restrictions.eq("department.id",existEmployee.getDepartment().getId()));
	    	  pageRequestBean.setDept(existEmployee.getDepartment().getId());
	    }
			pageRequestBean.setDate(serchdate);
			criteria.add(Restrictions.isNotNull("job"));
//			criteria.add(Restrictions.ge("tastproperty", 0));
			criteria.add(Restrictions.gt("tastproperty", 0));
			pageRequestBean.setCriteria(criteria);
			pageRequestBean.setStart(start);
			pageRequestBean.setLimit(limit);
			pageRequestBean.setPage(page);
			PageResponseBean pageResponseBean =jobDetailService.findJobDetail(pageRequestBean);
	        jobDetails=pageResponseBean.getRows();
	        int total=0;
	        total =pageResponseBean.getTotal();
			// 输出json内容到客户端
	        JSONSerializer jsonSerializer = new JSONSerializer();
	        jsonSerializer.include("*.id","*.name","*.employee","*.department","*.startdate","*.planCompleteDate","*.actualCompleteDate","*.jobRequirement",
	        		"*.step","*.core","*.actualcore");
	        jsonSerializer.exclude("*.class");
//	        jsonSerializer.exclude("*.class","*.jobDetails","*.records","*.weights","*.advice","*.employees","*.jobDetail");
	        jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	        String resultJson1 = jsonSerializer.deepSerialize(jobDetails);  
	        String resultJson2 =jsonSerializer.serialize(total);
	        System.out.println(resultJson2);
	        String jsonString = "{total:"+resultJson2.toString()+",jobDetails:"+resultJson1.toString()+"}";
	        System.out.print(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
			return NONE;
  }
// 创新性工作评价显示

public String  ListInnovativaJobdetails() throws Exception{
	if(jobId!=0){
		List<JobDetail> jobDetail=jobDetailService.findJobDetailByJobId(jobId);
		 int total=jobDetail.size();
			// 输出json内容到客户端
	        JSONSerializer jsonSerializer = new JSONSerializer();
	        jsonSerializer.exclude("*.class");

	        jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	        String resultJson1 = jsonSerializer.deepSerialize(jobDetail);  
	        String resultJson2 =jsonSerializer.serialize(total);
	        String jsonString = "{total:"+resultJson2.toString()+",jobDetails:"+resultJson1.toString()+"}";
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
	}
	
	
	
	return NONE;
	
}
public String  ListCreatJobDetail() throws Exception{
	  Employees  existEmployee =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
	  PageRequestBean pageRequestBean = new PageRequestBean();
			//封装条件
			DetachedCriteria criteria = DetachedCriteria.forClass(JobDetail.class);
		  if(serchdate==null || "".equals(serchdate)){
			    	 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			  	     Calendar  c = Calendar.getInstance();
			         c.set(Calendar.DAY_OF_YEAR, 1);//本年第一天
			         String first=sdf.format(c.getTime());
			         c.add(Calendar.YEAR, 1);
			         c.set(Calendar.DAY_OF_YEAR, 1);//本年最后一天
			         c.add(Calendar.DAY_OF_YEAR, -1);
			         String Last=sdf.format(c.getTime());
			         criteria.add(Restrictions.ge("startdate", sdf.parse(first)));
					 criteria.add(Restrictions.le("startdate", sdf.parse(Last)));
			    	
		  }
		  if(serchdate!=null && !"".equals(serchdate)){
				 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
				 int day=Integer.parseInt( serchdate.substring(5,7));
				 int year=Integer.parseInt( serchdate.substring(0,4));
				String  First =getFirstDayOfMonth(year,day);
				String  last =getLastDayOfMonth(year,day);
				criteria.add(Restrictions.ge("startdate", sdf.parse(First)));
				criteria.add(Restrictions.le("startdate", sdf.parse(last)));
			}
		  if(!existEmployee.getName().equals("admin")){
	    	  criteria.add(Restrictions.eq("department.id",existEmployee.getDepartment().getId()));
	    	  pageRequestBean.setDept(existEmployee.getDepartment().getId());
	    }
			pageRequestBean.setDate(serchdate);
			criteria.add(Restrictions.isNotNull("job"));
			criteria.add(Restrictions.eq("tastproperty", 0));
			pageRequestBean.setCriteria(criteria);
			pageRequestBean.setStart(start);
			pageRequestBean.setLimit(limit);
			pageRequestBean.setPage(page);
			PageResponseBean pageResponseBean =jobDetailService.findCraetJobDetail(pageRequestBean);
	        jobDetails=pageResponseBean.getRows();
	        int total=0;
	        total =pageResponseBean.getTotal();
			// 输出json内容到客户端
	        JSONSerializer jsonSerializer = new JSONSerializer();
	        jsonSerializer.include("*.id","*.name","*.employee","*.department","*.startdate","*.planCompleteDate","*.actualCompleteDate","*.jobRequirement",
	        		"*.step","*.core","*.actualcore");
	        jsonSerializer.exclude("*.class");
//	        jsonSerializer.exclude("*.class","*.jobDetails","*.records","*.weights","*.advice","*.employees","*.jobDetail");
	        jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	        String resultJson1 = jsonSerializer.deepSerialize(jobDetails);  
	        String resultJson2 =jsonSerializer.serialize(total);
	        System.out.println(resultJson2);
	        String jsonString = "{total:"+resultJson2.toString()+",jobDetails:"+resultJson1.toString()+"}";
	        System.out.print(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
			return NONE;
}

	/**
	  * 得到某年某月的第一天
	  *
	  * @param year
	  * @param month
	 */
 public String getFirstDayOfMonth(int year, int month)  {
	 
	  Calendar cal = Calendar.getInstance();
	 
	  cal.set(Calendar.YEAR, year);
	 
	  cal.set(Calendar.MONTH, month-1);
	  cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));	 
	
	  return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
}
 	/**
 	  * 得到某年某月的最后一天
 	  *
     * @param year
     * @param month
  */
 	 public  String getLastDayOfMonth(int year, int month) throws Exception {
 	 
     Calendar cal = Calendar.getInstance();
 	 
 	  cal.set(Calendar.YEAR, year);
 	  cal.set(Calendar.MONTH, month-1);
 	  cal.set(Calendar.DAY_OF_MONTH, 1);
 	  int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
 	  cal.set(Calendar.DAY_OF_MONTH, value);
	 	
 	  return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); 
 	 }
public void addJobDetail() throws Exception{
	    String FileName=null;
		// 添加附件
	   if(upload!=null){
		   ServletContext servletContext = ServletActionContext.getServletContext();
			String uploadDir = servletContext.getRealPath("/upload");
			//String url="upload/"+uploadFileName;
			// 写文件
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
			String someFileName = sdf1.format(new Date()) + uploadFileName;
			FileName=someFileName;
			InputStream in = new BufferedInputStream(new FileInputStream(upload));
			OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(uploadDir,someFileName)));// 真实文件名
			int b;
			while((b= in.read())!=-1){
				out.write(b);
			}
			in.close();
			out.close(); 
	   }
	   
		List<String> departments=new ArrayList<String>();
		List<String> persons=new ArrayList<String>();
		List<String> personbili=new ArrayList<String>();
		String checkStrings= ServletActionContext.getRequest().getParameter("flag");
		boolean n=false;
		String valueperson=ServletActionContext.getRequest().getParameter("empl");
		String buzhoubi=ServletActionContext.getRequest().getParameter("buzhoubili");
		String valuedepart=ServletActionContext.getRequest().getParameter("depar");
		String valueString=ServletActionContext.getRequest().getParameter("had");
		if(valueString.equals("")==false){
		String[] strings=valueString.split(",");
		for(int i=0;i<strings.length;i++){
//				String aString=strings[i];
				String a=strings[i].replace("[","").replace("]","");
				String[] strings1=a.split("-");
					departments.add(strings1[0]);
					persons.add(strings1[1]);
					personbili.add(strings1[2]);
				}
		 }

		if(checkStrings==null){
			n=false;
			 Job job=jobService.findJobById(jobDetail.getJob().getId());
			if(departments.size()>0&&persons.size()>0){
				for(int i=0;i<departments.size();i++){
				  JobDetail jobDetail1= new JobDetail();
				  Department department=departmentService.findByName(departments.get(i));
//				  Employees employees=employeeService.findEmployeesByName(persons.get(i));
				  Employees employees=employeeService.findEmployeesByNameAndDepart(persons.get(i), department);
				  jobDetail1.setName(jobDetail.getName());
				  jobDetail1.setDepartment(department);
				  jobDetail1.setEmployee(employees);
				  jobDetail1.setTastproperty(job.getNanyi());
				  jobDetail1.setCore(job.getCore()*Double.parseDouble(personbili.get(i))/100*(Double.parseDouble(buzhoubi))/100);
				  jobDetail1.setActualcore(job.getCore()*Double.parseDouble(personbili.get(i))/100*(Double.parseDouble(buzhoubi))/100);
			      jobDetail1.setJob(jobDetail.getJob());
			      jobDetail1.setStep(jobDetail.getStep());
			      jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
			      jobDetail1.setState("1");
			      jobDetail1.setPingji(1.0);
			      jobDetail1.setShu(1.0);
			      jobDetail1.setHandleState("1");
			      if(FileName!=null){
			    	  jobDetail1.setFujian(FileName);
			      }
			      jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
			      jobDetail1.setStartdate(jobDetail.getStartdate());
			      jobDetail1.setFlag(n);
			      jobDetail1.setSonid(i);
			         try {
						    jobDetailService.saveJobDetail(jobDetail1);
						  
							} catch (Exception e) {
								
								e.printStackTrace();
							}	
				}
//11				
				this.success=true;
				JSONSerializer jsonSerializer = new JSONSerializer();
				String resultJson =jsonSerializer.serialize(success);
				String jsonString = "{success:"+resultJson.toString()+"}";
				ServletActionContext.getResponse().setContentType("text;charset=utf-8");
				ServletActionContext.getResponse().getWriter().print(jsonString);
			}
			if(departments.size()==0&&persons.size()==0&&valuedepart.equals("请选择部门")==false&&valueperson.equals("请选择人员")==false){
				 Department department=departmentService.findByName(valuedepart);
//				 Employees employee =employeeService.findEmployeesByName(valueperson);
				 Employees employee =employeeService.findEmployeesByNameAndDepart(valueperson, department);
//				 Job job=jobService.findJobById(jobDetail.getJob().getId());
			     JobDetail jobDetail1= new JobDetail();
			     jobDetail1.setName(jobDetail.getName());
			     jobDetail1.setDepartment(department);
			     jobDetail1.setEmployee(employee);
			     jobDetail1.setTastproperty(job.getNanyi());
			     jobDetail1.setCore(jobDetail.getCore());
			     jobDetail1.setActualcore(job.getCore()*Double.parseDouble(buzhoubi)/100);
			     jobDetail1.setCore(job.getCore()*Double.parseDouble(buzhoubi)/100);
			     jobDetail1.setJob(jobDetail.getJob());
			     jobDetail1.setStep(jobDetail.getStep());
			     jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
			     jobDetail1.setState("1");
			     jobDetail1.setHandleState("1");
			     jobDetail1.setShu(1.0);
			     jobDetail1.setPingji(1.0);
			     if(FileName!=null){
			    	  jobDetail1.setFujian(FileName);
			      }
			     jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
			     jobDetail1.setStartdate(jobDetail.getStartdate());
			     jobDetail.setStartdate(jobDetail.getStartdate());
			     jobDetail1.setFlag(n);
			 try {
				    jobDetailService.saveJobDetail(jobDetail1);
				  
					} catch (Exception e) {
						
						e.printStackTrace();
					}	
//222
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			
			ServletActionContext.getResponse().setContentType("text;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);

				}
		}else{
			n=true;
		}
		//修改后的
		if(n==true){
		if(jobDetail.getStep()==1){
	    Job job=jobService.findJobById(jobDetail.getJob().getId());
		if(departments.size()>0&&persons.size()>0){
			for(int i=0;i<persons.size();i++){
			  JobDetail jobDetail1= new JobDetail();
			  Department department=departmentService.findByName(departments.get(i));
//			  Employees employees=	employeeService.findEmployeesByName();
			  Employees employees=	employeeService.findEmployeesByNameAndDepart(persons.get(i), department);
			  jobDetail1.setName(jobDetail.getName());
			  jobDetail1.setDepartment(department);
			  jobDetail1.setEmployee(employees);
			  jobDetail1.setTastproperty(job.getNanyi());
			  jobDetail1.setCore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
			  jobDetail1.setActualcore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
		      jobDetail1.setJob(jobDetail.getJob());
		      jobDetail1.setStep(jobDetail.getStep());
		      jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
		      jobDetail1.setState("1");
		      jobDetail1.setHandleState("1");
		      jobDetail1.setShu(1.0);
		      jobDetail1.setPingji(1.0);
		      if(FileName!=null){
		    	  jobDetail1.setFujian(FileName);
		      }
		      jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
		      jobDetail1.setStartdate(jobDetail.getStartdate());
		      jobDetail1.setFlag(n);
		      jobDetail1.setSonid(i);
		         try {
					    jobDetailService.saveJobDetail(jobDetail1);
					  
						} catch (Exception e) {
							
							e.printStackTrace();
						}	
			}
//3333
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			ServletActionContext.getResponse().setContentType("text;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);

		}
//		if(persons.size()==0&&departments.size()==0&&jobDetail.getStep()==1&&valuedepart.equals("请选择部门")==false&&valueperson.equals("请选择人员")==false){
//			Employees employee =employeeService.findEmployeesByName(valueperson);
////			 Job job=jobService.findJobById(jobDetail.getJob().getId());
//			 Department department=departmentService.findByName(valuedepart);
//		     JobDetail jobDetail1= new JobDetail();
//		     jobDetail1.setName(jobDetail.getName());
//		     jobDetail1.setDepartment(department);
//		     jobDetail1.setEmployee(employee);
//		     jobDetail1.setTastproperty(jobDetail.getTastproperty());
//		     jobDetail1.setCore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//		     jobDetail1.setActualcore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//		     jobDetail1.setJob(jobDetail.getJob());
//		     jobDetail1.setStep(jobDetail.getStep());
//		     jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
//		     jobDetail1.setState("1");
//		     jobDetail1.setHandleState("1");
//		     jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
//		     jobDetail1.setStartdate(jobDetail.getStartdate());
//		     jobDetail.setStartdate(jobDetail.getStartdate());
//		     jobDetail1.setFlag(n);
//		 try {
//			    jobDetailService.saveJobDetail(jobDetail1);
//			  
//				} catch (Exception e) {
//					
//					e.printStackTrace();
//				}	
//
//		this.success=true;
//		JSONSerializer jsonSerializer = new JSONSerializer();
//		String resultJson =jsonSerializer.serialize(success);
//		String jsonString = "{success:"+resultJson.toString()+"}";
//		System.out.println(jsonString);
//		ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
//		ServletActionContext.getResponse().getWriter().print(jsonString);
////		return NONE;
//			}
		
		}
	      if(jobDetail.getStep()>1){
	    	Job job=jobService.findJobById(jobDetail.getJob().getId());
			List<JobDetail> jobDetails=jobDetailService.findJobDetailByJobId(jobDetail.getJob().getId());
			List<JobDetail> jobDetails2=jobDetailService.findJobDetailByStepAndJobId(jobDetail.getStep()-1, jobDetail.getJob().getId());
//			if(jobDetails2.size()==1&&departments.size()==0&&persons.size()==0&&valuedepart.equals("请选择部门")==false
//					&&valueperson.equals("请选择人员")==false){
//				Employees employee =employeeService.findEmployeesByName(valueperson);
//				 Department department=departmentService.findByName(valuedepart);
//			     JobDetail jobDetail1= new JobDetail();
//			     jobDetail1.setName(jobDetail.getName());
//			     jobDetail1.setDepartment(department);
//			     jobDetail1.setEmployee(employee);
//			     jobDetail1.setTastproperty(jobDetail.getTastproperty());
//			     jobDetail1.setCore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//			     jobDetail1.setActualcore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//			     jobDetail1.setJob(jobDetail.getJob());
//			     jobDetail1.setStep(jobDetail.getStep());
//			     jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
//			     jobDetail1.setState("1");
//			     jobDetail1.setHandleState("1");
//			     jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
//			     jobDetail1.setStartdate(jobDetail.getStartdate());
//			     jobDetail.setStartdate(jobDetail.getStartdate());
//			     jobDetail1.setFlag(n);
//				 try {
//					    jobDetailService.saveJobDetail(jobDetail1);
//				 } catch (Exception e) {
//							e.printStackTrace();
//						}	
//				 this.success=true;
//					JSONSerializer jsonSerializer = new JSONSerializer();
//					String resultJson =jsonSerializer.serialize(success);
//					String jsonString = "{success:"+resultJson.toString()+"}";
//					System.out.println(jsonString);
//					ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
//					ServletActionContext.getResponse().getWriter().print(jsonString);
//				 
//			}
//	      if(jobDetails2.size()>1&&departments.size()==0&&persons.size()==0&&valuedepart.equals("请选择部门")==false
//					&&valueperson.equals("请选择人员")==false){
//				for(int i=0;i<jobDetails2.size();i++){
//					if(jobDetails2.get(i).isFlag()){
//							JobDetail jobDetail1= new JobDetail();
//							 Employees employees=	employeeService.findEmployeesByName(valueperson);
//							 Department department=departmentService.findByName(valuedepart);
//							  jobDetail1.setName(jobDetail.getName());
//							  jobDetail1.setDepartment(department);
//							  jobDetail1.setEmployee(employees);
//							  jobDetail1.setTastproperty(jobDetail.getTastproperty());
//							  jobDetail1.setCore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//							  jobDetail1.setActualcore(job.getCore()*Double.parseDouble(buzhoubi)/100);
//						         jobDetail1.setJob(jobDetail.getJob());
//						         jobDetail1.setStep(jobDetail.getStep());
//						         jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
//						         jobDetail1.setState("1");
//						         jobDetail1.setHandleState("1");
//						         jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
//						         jobDetail1.setStartdate(jobDetail.getStartdate());
//						        // jobDetail1.setFlag(jobDetail.isFlag());
//						         jobDetail1.setSonid(i);
//						         try {
//						 		    jobDetailService.saveJobDetail(jobDetail1);
//						 		  
//						 			} catch (Exception e) {
//						 				
//						 				e.printStackTrace();
//						 			}
//						        this.success=true;
//						 		JSONSerializer jsonSerializer = new JSONSerializer();
//						 		String resultJson =jsonSerializer.serialize(success);
//						 		String jsonString = "{success:"+resultJson.toString()+"}";
//						 		System.out.println(jsonString);
//						 		ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
//						 		ServletActionContext.getResponse().getWriter().print(jsonString);
//							}
//				}
//		 }else 
			 if(jobDetails2.size()==1&&departments.size()>0&&persons.size()>0){
				for(int i=0;i<persons.size();i++){
				  JobDetail jobDetail1= new JobDetail();
				  Department department=departmentService.findByName(departments.get(i));
//				  Employees employees=	employeeService.findEmployeesByName(persons.get(i));
				  Employees employees=	employeeService.findEmployeesByNameAndDepart(persons.get(i), department);
				  jobDetail1.setName(jobDetail.getName());
				  jobDetail1.setDepartment(department);
				  jobDetail1.setEmployee(employees);
				  jobDetail1.setTastproperty(job.getNanyi());
				  jobDetail1.setCore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
				  jobDetail1.setActualcore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
			      jobDetail1.setJob(jobDetail.getJob());
			      jobDetail1.setStep(jobDetail.getStep());
			      jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
			      jobDetail1.setState("1");
			      jobDetail1.setHandleState("1");
			      jobDetail1.setShu(1.0);
			      jobDetail1.setPingji(1.0);
			      if(FileName!=null){
			    	  jobDetail1.setFujian(FileName);
			      }
			      jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
			      jobDetail1.setStartdate(jobDetail.getStartdate());
			      jobDetail1.setFlag(n);
			      jobDetail1.setSonid(i);
			         try {
						    jobDetailService.saveJobDetail(jobDetail1);
						  
							} catch (Exception e) {
								
								e.printStackTrace();
							}
//4
			        this.success=true;
			 		JSONSerializer jsonSerializer = new JSONSerializer();
			 		String resultJson =jsonSerializer.serialize(success);
			 		String jsonString = "{success:"+resultJson.toString()+"}";
			 		ServletActionContext.getResponse().setContentType("text;charset=utf-8");
			 		ServletActionContext.getResponse().getWriter().print(jsonString);
				}
			}else{
				if(jobDetails2.size()>1&&departments.size()>0&&persons.size()>0){
					for(int i=0;i<persons.size();i++){
								JobDetail jobDetail1= new JobDetail();
//							  Employees employees=	employeeService.findEmployeesByName(persons.get(i));
							  Department department=departmentService.findByName(departments.get(i));
							  Employees employees=	employeeService.findEmployeesByNameAndDepart(persons.get(i), department);
							  jobDetail1.setName(jobDetail.getName());
							  jobDetail1.setDepartment(department);
							  jobDetail1.setEmployee(employees);
							  jobDetail1.setTastproperty(job.getNanyi());
							  jobDetail1.setCore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
							  jobDetail1.setActualcore(job.getCore()*Double.parseDouble(personbili.get(i))/100*Double.parseDouble(buzhoubi)/100);
						      jobDetail1.setJob(jobDetail.getJob());
						      jobDetail1.setStep(jobDetail.getStep());
						      jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
						      jobDetail1.setState("1");
						      jobDetail1.setHandleState("1");
						      jobDetail1.setPingji(1.0);
						      jobDetail1.setShu(1.0);
						      if(FileName!=null){
						    	  jobDetail1.setFujian(FileName);
						      }
						      jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
						      jobDetail1.setStartdate(jobDetail.getStartdate());
						      jobDetail1.setFlag(n);
						      jobDetail1.setSonid(i+100);
						         try {
									    jobDetailService.saveJobDetail(jobDetail1);
									  
										} catch (Exception e) {
											
											e.printStackTrace();
										}	
//55
						        this.success=true;
						 		JSONSerializer jsonSerializer = new JSONSerializer();
						 		String resultJson =jsonSerializer.serialize(success);
						 		String jsonString = "{success:"+resultJson.toString()+"}";
						 		ServletActionContext.getResponse().setContentType("text;charset=utf-8");
						 		ServletActionContext.getResponse().getWriter().print(jsonString);
					}
				}
			}
	   }
	}
}

//根据JOB 删除
public String deleteByJobId() throws Exception{
	try {
		jobDetailService.deleteJobDetailByjobId(jobId);
	} catch (Exception e) {
		e.printStackTrace();
	}
	this.success=true;
	JSONSerializer jsonSerializer = new JSONSerializer();
	String resultJson =jsonSerializer.serialize(success);
	String jsonString = "{success:"+resultJson.toString()+"}";
	System.out.println(jsonString);
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
	return NONE;
}
public void updatejobDetail() throws Exception{
	 Employees employee =employeeService.findEmployeesByName(jobDetail.getEmployee().getName());
	 Job job=jobService.findJobByName(jobDetail.getJob().getName());
	 JobDetail jobDetail2= new JobDetail();
	 jobDetail2.setId(jobDetail.getId());
     jobDetail2.setName(jobDetail.getName());
     jobDetail2.setDepartment(jobDetail.getDepartment());
     jobDetail2.setCore(jobDetail.getCore());
     jobDetail2.setJob(job);
     jobDetail2.setStep(jobDetail.getStep());
     jobDetail2.setEmployee(jobDetail.getEmployee());
     jobDetail2.setJobRequirement(jobDetail.getJobRequirement());
     jobDetail2.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
     jobDetail2.setStartdate(jobDetail.getStartdate());
	try {
	 jobDetailService.updataJobDetail(jobDetail2);
	} catch (Exception e) {
		
		e.printStackTrace();
	}	
	this.success=true;
	JSONSerializer jsonSerializer = new JSONSerializer();
	String resultJson =jsonSerializer.serialize(success);
	String jsonString = "{success:"+resultJson.toString()+"}";
	System.out.println(jsonString);
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
}
public String deletejobDetail(){ 
	jobDetailService.deleteJobDetailById(jobDetail.getId());
return NONE;
}
public String ListjobDetailByemp() throws Exception{
	jobDetails =new ArrayList<JobDetail>();
	Employees  existEmployee =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
	List<JobDetail> jobDetail1=jobDetailService.findJobDetailByEmpIdAndJob(existEmployee.getId(), null);
	for(int i=0;i<jobDetail1.size();i++){
		if(jobDetail1.get(i).getState().equals("1")&&jobDetail1.get(i).getJob().getState()==2){
			int jobId=jobDetail1.get(i).getJob().getId();
			List<JobDetail>  jobDetails2=jobDetailService.findJobDetailByJobId(jobId);
		     for(JobDetail jd:jobDetails2){
					//step是1的时候
             if(jobDetail1.get(i).getId()==jd.getId()&&jd.getStep()==1){
						  jobDetails.add(jd); 
						  
	                  } 
           //step是大于=2的时候
             if(jobDetail1.get(i).getId()==jd.getId()&&jd.getStep()>=2&&(jd.getSonid()-100)<0){
            	 List<JobDetail> jobDetails5= jobDetailService.findJobDetailByStepAndJobId(jd.getStep()-1, jobId);
            	 if(jobDetails5.size()==1&&jobDetails5.get(0).getState().equals("3")){
            		 jobDetails.add(jd); 
            	 }
            	 if(jobDetails5.size()>1){
            		 int num=0;
            		 for(int t=0;t<jobDetails5.size();t++){
            			 //根据flag做判断
            			 if(jobDetails5.get(t).isFlag()==false){
	            				 if(jobDetails5.get(t).getState().equals("3")){
	            				 num++;
		            			 if(num==jobDetails5.size()){
		            				 jobDetails.add(jd); 
		            			 }
	            			 }
            			 }
            			 if(jobDetails5.get(t).getState().equals("3")&&jobDetails5.get(t).getSonid()==jd.getSonid()&&jobDetails5.get(t).isFlag()==true){
            				 jobDetails.add(jd); 
            			 }else {
            				if(jobDetails5.get(t).getState().equals("3")&&jobDetails5.get(t).isFlag()==true){
								if((jobDetails5.get(t).getSonid()-100)==jd.getSonid()&&jobDetails5.get(t).getState().equals("3")){
									 jobDetails.add(jd); 
								}
            				}
						}
            		 }
            	 }	 
             }
             if(jobDetail1.get(i).getId()==jd.getId()&&jd.getStep()>=2&&(jd.getSonid()-100)>=0){
            	 List<JobDetail> jobDetails6= jobDetailService.findJobDetailByStepAndJobId(jd.getStep()-1, jobId);
            	for(int u=0;u<jobDetails6.size();u++){
            		if(jobDetails6.get(u).getState().equals("3")){
            			jobDetails.add(jd); 
            		}
            	}
             }
             
		}
	}
}	
	for(int i=0;i<jobDetail1.size();i++){
		System.out.println(jobDetail1.get(i));
		if(jobDetail1.get(i).getJob().getState()==2&&jobDetail1.get(i).getState().equals("2")){
			System.out.println(jobDetail1.get(i).getState());
			jobDetails.add(jobDetail1.get(i));
		}
	}
	JSONSerializer jsonSerializer = new JSONSerializer();
    jsonSerializer.exclude("*.class","*.jobDetails","*.records","*.weights","*.advice","*.employees","*.jobDetail");
    jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
    String resultJson1 = jsonSerializer.deepSerialize(jobDetails);  
    String jsonString = "{jobDetails:"+resultJson1.toString()+"}";
	System.out.println("我的任务+++++===:"+jsonString);
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
	return NONE;
}
/**
 * 无同步修改的显示个人临时性工作任务
 * @return
 * @throws Exception
 */
public String ListjobDetailByemp1() throws Exception{
	jobDetails =new ArrayList<JobDetail>();
	Employees  existEmployee =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
	 List<JobDetail> jobDetail1 = null;
	 if(!existEmployee.getName().equals("admin")){
		 jobDetail1=jobDetailService.findJobDetailByEmpIdAndJobAndstateAndTastproty(existEmployee.getId(), null, "3",0);
	 }
	JSONSerializer jsonSerializer = new JSONSerializer();
    jsonSerializer.exclude("*.class","*.jobDetails","*.advice","*.employees","*.jobDetail");
    jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
    String resultJson1 = jsonSerializer.deepSerialize(jobDetail1);  
    String jsonString = "{jobDetails:"+resultJson1.toString()+"}";
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
	return NONE;
}
/**
 * 显示创新型项目化工作
 * @return
 * @throws Exception
 */
public String ListCreatjobDetail() throws Exception{
	jobDetails =new ArrayList<JobDetail>();
	Employees  existEmployee =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
	 List<JobDetail> jobDetail1 = null;
	 if(!existEmployee.getName().equals("admin")){
		 jobDetail1=jobDetailService.findCreatJobDetail(existEmployee.getId(), null, "3",0);
	 }
	JSONSerializer jsonSerializer = new JSONSerializer();
    jsonSerializer.exclude("*.class","*.jobDetails","*.advice","*.employees","*.jobDetail");
    jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
    String resultJson1 = jsonSerializer.deepSerialize(jobDetail1);  
    String jsonString = "{jobDetails:"+resultJson1.toString()+"}";
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
	return NONE;
}
public String banli() throws Exception{
	  JobDetail jobDetail1=jobDetailService.findJobById(jobDetail.getId());
	  if(jobDetail1.getState().equals("1")){
		  	jobDetail1.setState("2");
			jobDetailService.updataJobDetail(jobDetail1);
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			System.out.println(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);  
	  }else{
		  throw new RuntimeException("项目正在办理中");
	  }
		return NONE;
	
 }
public String huifu() throws Exception{
	  JobDetail jobDetail1=jobDetailService.findJobById(jobDetail.getId());
	
		  	jobDetail1.setHuifu(jobDetail.getHuifu());
			jobDetailService.updataJobDetail(jobDetail1);
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			System.out.println(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);  
		return NONE;
}
public String wancheng() throws Exception{
	  int all=0;
	  JobDetail joDetail1=jobDetailService.findJobById(jobDetail.getId());
//	  List<JobDetail> joDetail1=jobDetailService.findJobDetailByStep(joDetail.getStep()+1, joDetail.getJob().getId());
	  if(joDetail1.getState().equals("2")){
		    Date d=new Date();
		    if(d.getTime()>joDetail1.getPlanCompleteDate().getTime()){
		    	 joDetail1.setHandleState("2");
		    }else{
		    	 joDetail1.setHandleState("1");
		    }
		    joDetail1.setActualCompleteDate(d);
		   
		    joDetail1.setState("3");
			jobDetailService.updataJobDetail(joDetail1);
			Job job=jobService.findJobById(joDetail1.getJob().getId());
			List<JobDetail>	jobDetails=jobDetailService.findJobDetailByJobId(job.getId());
			for(int i=0;i<jobDetails.size();i++){
				if(jobDetails.get(i).getState().equals("3")){
					all=all+1;
				}
				if(all==jobDetails.size()){
					
					job.setState(3);
					jobService.updateJobs(job);	
				}
			}
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			System.out.println(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
	  }else{
		  throw new RuntimeException("项目还未办理");
	  }
		
	return NONE;
}
public String wanchengWeekjob() throws Exception{
	  JobDetail joDetail1=jobDetailService.findJobById(jobDetail.getId());
	  if(joDetail1.getState().equals("2")){
		    Date d=new Date();
		    joDetail1.setActualCompleteDate(d);
		    joDetail1.setState("3");
			jobDetailService.updataJobDetail(joDetail1);
			this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			System.out.println(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
	  }else{
		  throw new RuntimeException("项目还未办理");
	  }
		
	return NONE;
}
public String deleteWeekjob() throws Exception{
//	  JobDetail joDetail1=jobDetailService.findJobById(jobDetail.getId());
	    jobDetailService.deleteJobDetailById(jobDetail.getId());
	return NONE;
}
	public String addRemark() throws Exception{
		  JobDetail jobDetail1=jobDetailService.findJobById(jobDetail.getId());
		  List<JobDetail> jobDetail2=jobDetailService.findJobDetailByStepAndJobId(jobDetail1.getStep()+1, jobDetail1.getJob().getId());
//		  List<JobDetail> jobDetail2=jobDetailService.findJobDetailByStep1(jobDetail1.getStep()+1, jobDetail1.getJob().getId());
		  try {
			
			if(jobDetail2!=null){
				for(int i=0;i<jobDetail2.size();i++){
					jobDetail2.get(i).setRemark(jobDetail.getRemark());
					jobDetailService.updataJobDetail(jobDetail2);
				}
			}
		} catch (Exception e) {
		
			e.printStackTrace();
		}
		  this.success=true;
			JSONSerializer jsonSerializer = new JSONSerializer();
			String resultJson =jsonSerializer.serialize(success);
			String jsonString = "{success:"+resultJson.toString()+"}";
			System.out.println(jsonString);
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
		return NONE;
	}
	//修改实际得分
	public String editActualcore() throws Exception {
		 for(int i=0;i<ids.length;i++){
	           jobDetailService.updateBatch(cores[i]*pingjis[i],pingjis[i],ids[i]);
			  }
	     this.success=true;
		 JSONSerializer jsonSerializer = new JSONSerializer();
	     String resultJson =jsonSerializer.serialize(success);
	     String jsonString = "{success:"+resultJson.toString()+"}";
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(jsonString);
			return NONE;   
		}
	//添加流程任务
	public void addjob() throws Exception{
		String person=ServletActionContext.getRequest().getParameter("emp");
		String depart=ServletActionContext.getRequest().getParameter("dep");
		   Department d=departmentService.findByName(depart);
		   Employees E=employeeService.findEmployeesByName(person);
	       JobDetail jobDetail1= new JobDetail();
	       jobDetail1.setName(jobDetail.getName());
	       jobDetail1.setDepartment(d);
	       jobDetail1.setEmployee(E);
	       jobDetail1.setCycle(jobDetail.getCycle());
	       jobDetail1.setJobRequirement(jobDetail.getJobRequirement());
	       jobDetail1.setState(jobDetail.getState());
//	       jobDetail1.setPingji(1.00);
	       jobDetail1.setPlanCompleteDate(jobDetail.getPlanCompleteDate());
	       jobDetail1.setStartdate(jobDetail.getStartdate());
		 try {
			    jobDetailService.saveJobDetail(jobDetail1);
				} catch (Exception e) {	
					e.printStackTrace();
				}	
	this.success=true;
	JSONSerializer jsonSerializer = new JSONSerializer();
	String resultJson =jsonSerializer.serialize(success);
	String jsonString = "{success:"+resultJson.toString()+"}";
	System.out.println(jsonString);
	ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	ServletActionContext.getResponse().getWriter().print(jsonString);
			
		}
	//程序化工作评价显示
	public String  ListJob() throws Exception{

		Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
		if(!e.getName().equals("admin")){
			 jobDetails=jobDetailService.findJobDetailByJobAndDepart(null, e.getDepartment().getId());
		}
		int total=0;
	     total= jobDetails.size();
       JSONSerializer jsonSerializer = new JSONSerializer();
       jsonSerializer.include("*.id","*.name","*.employee","*.department","*.startdate","*.planCompleteDate","*.actualCompleteDate","*.jobRequirement");
       jsonSerializer.exclude("*.class","*.jobDetails","*.records","*.weights","*.advice","*.employees","*.jobDetail");
       jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
       String resultJson1 = jsonSerializer.deepSerialize(jobDetails);  
       String resultJson2 =jsonSerializer.serialize(total);
       System.out.println(resultJson2);
       String jsonString = "{total:"+resultJson2.toString()+",jobDetails:"+resultJson1.toString()+"}";
       System.out.print(jsonString);
		ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
		ServletActionContext.getResponse().getWriter().print(jsonString);
		return NONE;
 }
	
	//评价显示周工作计划详情
	public String  ListProcedureJobDetail() throws Exception{
		    Rate  rate=rateService.findRateById(RateID);
//			JobDetail jobDetail=jobDetailService.findById(jobId);
		    List<JobDetail> jobDetails=jobDetailService.findJobDetailByEmpAndDateAndJob(rate.getEmployee().getId(),(rate.getDate()+"-01"),null);
		
	  int  total= jobDetails.size();
      JSONSerializer jsonSerializer = new JSONSerializer();
      jsonSerializer.include("*.id","*.name","*.employee","*.department","*.startdate","*.planCompleteDate","*.actualCompleteDate","*.jobRequirement");
      jsonSerializer.exclude("*.class","*.jobDetails","*.records","*.weights","*.advice","*.employees","*.jobDetail");
      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
      String resultJson1 = jsonSerializer.deepSerialize(jobDetails);  
      String resultJson2 =jsonSerializer.serialize(total);
      String jsonString = "{total:"+resultJson2.toString()+",jobDetails:"+resultJson1.toString()+"}";
	  ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
	  ServletActionContext.getResponse().getWriter().print(jsonString);
	  return NONE;
}
	public String pingji() throws Exception {
		 for(int i=0;i<ids.length;i++){
			 JobDetail j1=jobDetailService.findById(ids[i]);
			 List<JobDetail> j2=jobDetailService.findJobDetailByJobAndStartDateAndDepart(null, j1.getStartdate().toString(),j1.getDepartment().getId());
			 for( JobDetail j: j2){
//				   j.setPingji(pingjis[i]);
		           jobDetailService.updataJobDetail(j);
			 }
		 }
		 
	     this.success=true;
		 JSONSerializer jsonSerializer = new JSONSerializer();
	     String resultJson =jsonSerializer.serialize(success);
	     String jsonString = "{success:"+resultJson.toString()+"}";
		 ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
		 ServletActionContext.getResponse().getWriter().print(jsonString);
			return NONE;   
		}
	//显示周任务
	public String  ListWeekProcedure() throws Exception{
	  Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
//	  	Date d= new Date();
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//		String dateString = formatter.format(d);
	  jobDetails1=jobDetailService.findByweekJob(e.getId(), null,"3");
      JSONSerializer jsonSerializer = new JSONSerializer();
      jsonSerializer.exclude("*.class","*.jobDetails","*.employees","*.jobDetail","*.job");
      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
      String result = jsonSerializer.deepSerialize(jobDetails1);  
      String json = "{jobDetails:"+result.toString()+"}";
      System.out.print(json);
		ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
		ServletActionContext.getResponse().getWriter().print(json);
		return NONE;
	}
// 显示所有的程序化工作，默认当月
	public String  ListMyMonthProcedure() throws Exception{
		
		    Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
		    if(!(serchdate==null)){
		    	jobDetails1=jobDetailService.findCXJobDetailByEmpAndDateAndJob(e.getId(), serchdate, null);
		    }else{
		    	Date d= new Date();
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
				String dateString = formatter.format(d);
				jobDetails1=jobDetailService.findCXJobDetailByEmpAndDateAndJob(e.getId(), dateString, null);
		    }
		  	
	      JSONSerializer jsonSerializer = new JSONSerializer();
	      jsonSerializer.exclude("*.class");
	      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	      String result = jsonSerializer.deepSerialize(jobDetails1);  
	      String json = "{jobDetails:"+result.toString()+"}";
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(json);
			return NONE;
		}
	// 显示所有的临时性工作，默认当月
public String  ListMyXMjobs() throws Exception{
			
			    Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
			    if(!(serchdate==null)){
			    	jobDetails1=jobDetailService.findLXMJobDetailByEmpAndDateAndJob(e.getId(), serchdate, null,0);
			    }else{
			    	Date d= new Date();
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
					String dateString = formatter.format(d);
					jobDetails1=jobDetailService.findLXMJobDetailByEmpAndDateAndJob(e.getId(), dateString, null,0);
			    }
			  	
		      JSONSerializer jsonSerializer = new JSONSerializer();
		      jsonSerializer.exclude("*.class");
		      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
		      String result = jsonSerializer.deepSerialize(jobDetails1);  
		      String json = "{jobDetails:"+result.toString()+"}";
				ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
				ServletActionContext.getResponse().getWriter().print(json);
				return NONE;
			}
// 显示所有的创新性工作，默认当月
public String  ListMyCreatJobs() throws Exception{

		    Employees  e =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
		    if(!(serchdate==null)){
		    	jobDetails1=jobDetailService.findCreatXMJobDetail(e.getId(), serchdate, null,0);
		    }else{
		    	Date d= new Date();
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
				String dateString = formatter.format(d);
				jobDetails1=jobDetailService.findCreatXMJobDetail(e.getId(), dateString, null,0);
		    }
		  	
	      JSONSerializer jsonSerializer = new JSONSerializer();
	      jsonSerializer.exclude("*.class");
	      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	      String result = jsonSerializer.deepSerialize(jobDetails1);  
	      String json = "{jobDetails:"+result.toString()+"}";
			ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().print(json);
			return NONE;
}
	// 查看个人项目化工作详情
	public String  ListpersonXMjob() throws Exception{
		
		  jobDetails1=jobDetailService.findXMJobDetailByEmpAndDateAndJob(searchemp, searchdate+"-01", null);
	      JSONSerializer jsonSerializer = new JSONSerializer();
	      jsonSerializer.include("*.id","*.name","*.employee","*.department","*.startdate","*.planCompleteDate","*.actualCompleteDate","*.jobRequirement");
	      jsonSerializer.exclude("*.class");
	      jsonSerializer.transform(new DateTransformer("yyyy-MM-dd"),Date.class);
	      String result = jsonSerializer.deepSerialize(jobDetails1);  
	      String json = "{jobDetails:"+result.toString()+"}";
		  ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
		  ServletActionContext.getResponse().getWriter().print(json);
			return NONE;
		}
	//添加个人周计划
		public void addplanjob() throws Exception{
			Employees  emp =(Employees) ServletActionContext.getRequest().getSession().getAttribute("existEmployee");
			Date d=new Date();
			Date d1=getDateAfter(d,4);
			if(creatdate.equals("")){
				for(int i=0;i<names.length;i++){
					 JobDetail jobDetail1= new JobDetail();
				       jobDetail1.setName(names[i]);
				       jobDetail1.setDepartment(emp.getDepartment());
				       jobDetail1.setEmployee(emp);
				       jobDetail1.setJobRequirement(adcontents[i]);
				       jobDetail1.setState("1");
//				       jobDetail1.setCore(1.0);
				       jobDetail1.setShu(1.0);
				       jobDetail1.setStartdate(d);
				       jobDetail1.setPlanCompleteDate(d1);
					   jobDetailService.saveJobDetail(jobDetail1);
				}
			}else{
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
				 Date plantdate = formatter.parse(creatdate);
				 Date d2=getDateAfter(plantdate,4);
				for(int i=0;i<names.length;i++){
					 JobDetail jobDetail1= new JobDetail();
				       jobDetail1.setName(names[i]);
				       jobDetail1.setDepartment(emp.getDepartment());
				       jobDetail1.setEmployee(emp);
				       jobDetail1.setJobRequirement(adcontents[i]);
				       jobDetail1.setState("1");
//				       jobDetail1.setCore(1.0);
				       jobDetail1.setShu(1.0);
				       jobDetail1.setStartdate(plantdate);
				       jobDetail1.setPlanCompleteDate(d2);
					   jobDetailService.saveJobDetail(jobDetail1);
				}	
			}
			
		      
		this.success=true;
		JSONSerializer jsonSerializer = new JSONSerializer();
		String resultJson =jsonSerializer.serialize(success);
		String jsonString = "{success:"+resultJson.toString()+"}";
		System.out.println(jsonString);
		ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
		ServletActionContext.getResponse().getWriter().print(jsonString);
				
			}
		
		// 获得后几天的时间
public static Date getDateAfter(Date d,int day){  
				   Calendar now =Calendar.getInstance();  
				   now.setTime(d);  
				   now.set(Calendar.DATE,now.get(Calendar.DATE)+day);  
				   return now.getTime();  
}  
public String download () {
			JobDetail j=jobDetailService.findById(jobId);
      if(j!=null){
		    	if(null==j.getFujian()){
		    		  throw new RuntimeException("无附件可以下载");
		    	}
		    	
		    }
			 
			return NONE;
		}
		
		
}

